// cookbook数据处理 模型层
import { get } from '../api/net'
import config from '../config/uri'

class CookbookModel {
    // swiper数据获取
    async getSwiperData() {
        let ret = await get(config.swiper)
        return ret
    }

    // 热门分类
    async getHotCateData() {
        let ret = await get(config.hotcate)
        let data = ret.data.map((item, index) => ({ id: index, text: item.title }))
        return data
    }

    // 精品好菜
    async getGoodCookbookData() {
        let ret = await get(config.list)
        return ret.data.data.slice(0, 20)
    }

    // 分类列表
    async getCategoryData() {
        let ret = await get(config.category)
        let data = ret.data.data.category
        let result = []
        for (let key in data) {
            var tmp = {}
            tmp = {
                name: key,
                data: data[key]
            }
            result.push(tmp)
        }

        return result;
    }

    // 分类列表
    async getMaterialData() {
        let ret = await get(config.category)
        let data = ret.data.data.material
        let result = []
        for (let key in data) {
            var tmp = {}
            tmp = {
                name: key,
                data: data[key]
            }
            result.push(tmp)
        }
        return result;
    }


}


export default new CookbookModel()